package com.luojing.springcloud.controller;/**
 * Created by luojing on 2017/6/6.
 */

import com.luojing.springcloud.config.alimq.Producer1;
import com.luojing.springcloud.kafka.Producer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.kafka.support.KafkaHeaders;
import org.springframework.messaging.Message;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author
 * @create 2017-06-06 14:35
 **/
@RestController
public class IndexController {

    private static final Logger logger = LoggerFactory.getLogger(IndexController.class);

//    @Autowired
//    private Sender sender;
//
//    @Autowired
//    private SenderFanout senderFanout;

    @Autowired
    private Producer1 producer1;

    @Autowired
    private Producer producer;

//    @RequestMapping(value = "/hello")
//    public String hello(){
//        sender.send();
//        return "hello";
//    }
//
//    @RequestMapping(value = "/helloFanout")
//    public String helloFanout(){
//        senderFanout.send();
//        return "helloFanout";
//    }

    @RequestMapping(value = "/kafka/hello")
    public String kafkaHello(){
        producer.send();
        return "kafka/hello";
    }

    @RequestMapping(value = "/zipkin/hello")
    public String zipkin(){
        return "zipkin/hello";
    }

    @RequestMapping(value = "/zipkin/hello1")
    public String zipkin1(){
        logger.info("z1");
        return "zipkin/hello1";
    }

//    @Bean
//    public AlwaysSampler defaultSampler(){
//        return new AlwaysSampler();
//    }

    @Autowired
    private Source source;
    @RequestMapping(value = "/sendAlimq")
    public String sendAlimq(){
        //producer1.send("123","smart_life_test");
        Message<String> message = MessageBuilder.withPayload("Hello Aliyun Kafka")
                .setHeader(KafkaHeaders.MESSAGE_KEY, "1".getBytes())
                .build();
        source.output().send(message);
        return "success";
    }

}
